package com.duck.base.oauth.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import com.duck.base.oauth.security.model.DuckUserDetails;
import com.duck.sys.entity.User;
import com.duck.sys.service.IUserService;

@Component
public class DuckUserDetailService implements UserDetailsService {

	@Autowired
	private IUserService userService;
	
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		// TODO Auto-generated method stub
		User user =  userService.queryByUserName(username);
		if(user==null) {
			return null;
		}
		return new DuckUserDetails(user);
	}

}
